<template>
  <div class="box">
    <div class="userinfo">
      <img
        v-if="commentDate.user.head_img"
        :src="$axios.defaults.baseURL + commentDate.user.head_img"
        alt=""
      />
      <img v-else src="../../assets/logo1.jpg" alt="" />
      <div class="info">
        <div class="author">
          {{ commentDate.user.nickname }}
        </div>
        <div class="date">2小时前</div>
      </div>
      <div class="huifu" @click="sendComment">回复</div>
    </div>
    <!-- !!!不要把parent不该大写的地方大写了！！ -->
    <Parent :parentData="commentDate.parent" v-if="commentDate.parent" />
    <div class="maincontent">
      {{ commentDate.content }}
    </div>
  </div>
</template>

<script>
import Parent from "./Parent";
import eventBus from "../../utils/eventBus";
export default {
  components: {
    Parent,
  },
  props: ["commentDate"],
  methods: {
    sendComment() {
      // 引入了一个eventBus vue实例
      // 可以用$emit给这个实例发送触发事件（相当于是对父组件传值）
      eventBus.$emit(
        "sendMsg",
        this.commentDate.id,
        this.commentDate.user.nickname
      );
    },
  },
};
</script>

<style lang="less" scoped>
.box {
  padding: 10 / 360 * 100vw;
  border-bottom: 1px solid #ccc;
  .userinfo {
    display: flex;
    margin-bottom: 4 / 360 * 100vw;
    // align-items: center;
    img {
      width: 35 / 360 * 100vw;
      height: 35 / 360 * 100vw;
      border-radius: 50%;
      object-fit: cover;
    }
    .info {
      flex-grow: 1;
      padding-left: 10 / 360 * 100vw;
      .author {
        font-size: 14 / 360 * 100vw;
        color: #333;
      }
      .date {
        font-size: 12 / 360 * 100vw;
        color: #888;
      }
    }
    .huifu {
      font-size: 14 / 360 * 100vw;
      color: #888;
    }
  }
  .maincontent {
    font-size: 16 / 360 * 100vw;
    color: #333;
    margin-top: 6 / 360 * 100vw;
    text-indent: 20px;
    // 当评论输入过长时：可以用word-break：break-all断行
    word-break: break-all;
  }
}
</style>